// 新增配置类：注册WebSocket处理器
package zhongbo.java.air.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import zhongbo.java.air.monitor.web.websocket.AlertZoneWebSocket;
import zhongbo.java.air.web.websocket.LiveWebSocket;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private LiveWebSocket liveWebSocket;

    @Autowired
    private AlertZoneWebSocket alertZoneWebSocket; // 新增：注入 AlertZoneWebSocket

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(liveWebSocket, "/websocket/live") // 注册路径
               .setAllowedOrigins("*"); // 允许跨域

        registry.addHandler(alertZoneWebSocket, "/websocket/alert") // 新增：注册路径
               .setAllowedOrigins("*"); // 允许跨域
    }
}